package com.athenaeum.dataxplore.controller;

import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.athenaeum.datastore.domain.User;
import com.athenaeum.datastore.service.UserService;

@Controller
public class ProfileController {
	private static final Logger logger = LoggerFactory
			.getLogger(ProfileController.class);
	@Autowired
	private UserService userService;

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/profile/{id:.+}", method = RequestMethod.GET)
	public String profile(Locale locale, Model model, @PathVariable String id) {
		logger.info("Loading Profile Page... ID - " + id);
		User user = userService.findOne(id);
		// TODO Use rating/mru and retrive the best
		model.addAttribute("projects", user.getProjects().values());
		model.addAttribute("profile", user);
		return "profile";
	}
}
